<template>
  <ux-table-column-wrapper v-if="hasComponentAttrsField(this,'ux-grid') && $scopedSlots.edit" v-bind="$attrs">
    <template v-slot:edit="scope">
      <slot name="edit" :row="scope.row"></slot>
    </template>
  </ux-table-column-wrapper>
  <ux-table-column-wrapper v-else-if="hasComponentAttrsField(this,'ux-grid') && $scopedSlots.default" v-bind="$attrs">
    <template v-slot="scope">
      <slot :row="scope.row"></slot>
    </template>
  </ux-table-column-wrapper>
  <ux-table-column-wrapper v-else-if="hasComponentAttrsField(this,'ux-grid')" v-bind="$attrs"/>

  <u-table-column-wrapper v-else-if="$scopedSlots.default" v-bind="$attrs" v-on="$listeners">
    <template slot-scope="{row}">
      <slot :row="row"></slot>
    </template>
  </u-table-column-wrapper>
  <u-table-column-wrapper v-else-if="hasComponentAttrsField(this,'u-table')" v-bind="$attrs" v-on="$listeners"
                          @search="search('u-table')"/>

  <el-table-column-wrapper v-else-if="$scopedSlots.default" v-bind="$attrs" v-on="$listeners">
    <template slot-scope="{row}">
      <slot :row="row"></slot>
    </template>
  </el-table-column-wrapper>
  <el-table-column-wrapper v-else v-bind="$attrs" v-on="$listeners" @search="search('el-table')"/>
</template>

<script>
  import ElTableColumnWrapper from './ElTableColumnWrapper'
  import UTableColumnWrapper from './UTableColumnWrapper'
  import UxTableColumnWrapper from './UxTableColumnWrapper'
  import {findComponent, hasComponentAttrsField} from '@/utils/find'

  export default {
    components: {
      ElTableColumnWrapper,
      UTableColumnWrapper,
      UxTableColumnWrapper
    },
    methods: {
      hasComponentAttrsField,
      search(tableName) {
        const table = findComponent(this, tableName)
        table.$listeners.search()
      }
    }
  }
</script>